var webpack = require('webpack');
var htmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
    entry: {
        // article:'./src/js/article.js',
        /*about:'./src/js/about.js'*/
        // 'exam-report':'./src/js/exam-report.js',
        'question':'./src/js/question.js',
    },
    output: {
        path: __dirname + '/dist',
        filename: 'js/[name].js?v=[chunkhash:6]',
    },
    module: {
        rules: [{ 
            test: /\.css$/,
            use: ExtractTextPlugin.extract({
                fallback: 'style-loader',
                use: [{
                    loader: 'css-loader',
                    options: {
                        minimize: true //css压缩
                    }
                }]
            })
        }, { 
            test: /\.less$/, 
            use: ExtractTextPlugin.extract({
                fallback: 'style-loader',
                use: [{
                    loader: 'css-loader',
                    options: {
                        minimize: true //css压缩
                    }
                }, {
                    loader: 'postcss-loader',
                    options: {
                        plugins: [require('autoprefixer')(), require('postcss-import')()]
                    }
                }, {
                    loader:'less-loader',
                }],
            })
        }, {
            test: /\.js$/, 
            use:[{
                loader: 'babel-loader',
                options: {
                    presets: ['env']
                },
            }],
            exclude: path.resolve(__dirname, 'node_modules'),
            include: path.resolve(__dirname, 'src')
        }, {
            test: /\.(png|jpg|gif|svg)$/,
            use: [{
                loader: 'file-loader',
                /*options: {
                    name: 'img/[name].[ext]'
                }*/
            }],
        }, {
            test: /\.vue$/,
            use: ['vue-loader'],
        }]
    },
    plugins: [
        new webpack.ProvidePlugin({
          $: 'jquery',
        }),
        // new htmlWebpackPlugin({
        //     template: './src/article.html',
        //     chunks: ['article'],
        //     filename: 'article.html',
        // }),
        // new htmlWebpackPlugin({
        //     template: './src/exam-report.html',
        //     chunks: ['exam-report'],
        //     filename: 'exam-report.html',
        // }),
        new htmlWebpackPlugin({
            template: './src/question.html',
            chunks: ['question'],
            filename: 'question.html',
        }),
        /*new htmlWebpackPlugin({
            template: './src/about.html',
            chunks: ['about'],
            filename: 'about.html',
            inject: false,
            minify: {
                removeComments: true,
                collapseWhitespace: true,
            },
        }),*/
        new ExtractTextPlugin('css/[name].css?v=[chunkhash:6]'),
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        }),
    ],
    devServer: {
        contentBase: "./dist",//本地服务器所加载的页面所在的目录
        historyApiFallback: true,//不跳转
        inline: true,//实时刷新
        disableHostCheck: true,
        host: '0.0.0.0'
    }
}